<!DOCTYPE html>
<html lang="en">

<head>
    {include file="common/meta" /}
</head>

<body>
    <div class="x-body">

        <!-- 搜索 -->
        <div class="layui-row">
            <form method="get" class="layui-form layui-col-md12 x-so">
                <input class="layui-input" placeholder="开始日" name="start" id="start" value="" />

                <input class="layui-input" placeholder="截止日" name="end" id="end" value="" />

                <input type="text" name="keywords" placeholder="" autocomplete="off" value="" class="layui-input">

                <button class="layui-btn">
                    <i class="layui-icon">&#xe615;</i>
                </button>
            </form>
        </div>

        <xblock>
            <button class="layui-btn layui-btn-danger" onclick="delAll()">
                <i class="layui-icon"></i>批量删除
            </button>

            <span class="x-right" style="line-height:40px">
                共有数据：{$count} 条
            </span>
        </xblock>

        <table class="layui-table">
            <thead>
                <tr>
                    <th>
                        <div class="layui-unselect header layui-form-checkbox" lay-skin="primary"><i
                                class="layui-icon">&#xe605;</i>
                        </div>
                    </th>
                    <th>标题</th>
                    <th>所属分类</th>
                    <th>悬赏积分</th>
                    <th>发布人</th>
                    <th>访问次数</th>
                    <th>帖子状态</th>
                    <th>附加功能</th>
                    <th>发布时间</th>
                    <th>操作</th>
            </thead>

            <tbody>
                {foreach $postlist as $item}
                <tr>
                    <td>
                        <div class="layui-unselect layui-form-checkbox" lay-skin="primary" data-id="{$item.id}">
                            <i class="layui-icon">&#xe605;</i>
                        </div>
                    </td>
                    <td>{$item.title}</td>
                    <td>{$item.cate.name}</td>
                    <td>{$item.point}</td>
                    <td>{$item.user.nickname}</td>
                    <td>{$item.visit_text}</td>
                    <td>{$item.accept ? '完结' : '未结'}</td>
                    <td>{$item.state_text}</td>
                    <td>{$item.createtime}</td>
                    <td class="td-manage" style="display:inline-flex;">
                        <a target="_blank" title="修改用户信息" class="layui-btn layui-btn-sm layui-btn-normal"
                            href="{:url('home/index/info', ['postid' => $item['id']])}" style="width: 80px;">
                            查看详情
                        </a>

                        <a title="删除" class="layui-btn layui-btn-sm layui-btn-danger" onclick="del(`{$item['id']}`)"
                            href="javascript:;" style="width: 50px;">
                            删除
                        </a>
                    </td>
                </tr>
                {/foreach}
            </tbody>
        </table>

        <div class="page">
            {$pagestr}
        </div>

    </div>
</body>

</html>
<script>
    layui.use('laydate', function () {
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#start' //指定元素
        });

        //执行一个laydate实例
        laydate.render({
            elem: '#end' //指定元素
        });


    });

    function del(data) {
        layer.confirm('确认要删除吗？', function (index) {
            layer.close(index);
            deletes(data)
        })

    }

    function delAll() {
        var ids = tableCheck.getData()
        layer.confirm('确认要删除吗？', function (index) {
            //将数组转换为字符串
            var data = ids.join(',');
            del(data)
        })
    }

    function deletes(data) {

        //序列化 将对象转换为参数形式
        var params = {
            ids: data
        }

        params = $.param(params)

        $.ajax({
            type: "POST",
            url: `{:url('admin/post.post/del')}`,
            data: params,
            dataType: "json",
            success: function (data) {
                layer.msg(data.msg, {
                    icon: 5,
                    time: 1000
                }, function () {
                    location.reload()
                })
            }
        })
    }
</script>